package cn.cd.anStudio.CommonUtil;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Handler;  
import android.os.Looper;  
import android.os.Message;

public class AnstudioSynDialog extends AlertDialog {

    int dialogResult;  
    Handler mHandler; 
      
    public AnstudioSynDialog(Activity context, String content, String button1Content, String button2Content)  
    {
        super(context);  
        setOwnerActivity(context);  
        
        android.content.DialogInterface.OnClickListener synDialogListener =
    			new android.content.DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						endDialog(which);
					}
    	};
    	
    	this.setMessage(content);
    	this.setButton(button1Content, synDialogListener);
    	if (null != button2Content)
    		this.setButton2(button2Content, synDialogListener);
    }
    
    public int getDialogResult()  
    {  
        return dialogResult;  
    }
    
    public void setDialogResult(int dialogResult)  
    {  
        this.dialogResult = dialogResult;  
    }  
       
    public void endDialog(int result)  
    {  
        dismiss();  
        setDialogResult(result);  
        Message m = mHandler.obtainMessage();  
        mHandler.sendMessage(m);  
    }  
      
    @SuppressWarnings("static-access")
	public int showDialog()  
    {  
        mHandler = new Handler() {  
            @Override  
              public void handleMessage(Message mesg) {  
                // process incoming messages here  
                //super.handleMessage(msg);  
                throw new RuntimeException();  
              }  
          };
          
        super.show();  
        
        try {
            Looper.getMainLooper().loop();  
        }  
        catch(RuntimeException e2)  
        {  
        }
        
        return dialogResult;  
    }  
      
}  